/****************************** (C) COPYRIGHT 2016 RSEStudio ****************************
* File Name          : 
* Author             : RSES_Liyang
* Version            : V1.0.0
* Date               : 00-May-18
* Description        : 
*****************************************************************************************/

#ifndef __BSP_H__
#define __BSP_H__

/* Includes ----------------------------------------------------------------------------*/
#include <stdint.h>
/* Exported types ----------------------------------------------------------------------*/

//******************************************************************************************************** 
#define DEV_TYPE_I7                 1
#define DEV_TYPE_XP                 2
#define DEV_TYPE_MINI               3
#define DEV_TYPE_VACUUM             4

#define DEV_TYPE_OXYGEN_STD         6

#define DEV_TYPE_RPT_STD            8


#define DEV_TYPE_RCMK_STD           12

//*************************************************************************************************

#define DEV_TYPE					1	//1:i7   2:XP   3:mini   4:Vacuum   6:Oxygen_Std    8:RPT   10:RSV    12:RCMK

//*************************************************************************************************
//*************************************************************************************************

#define FW_VER_MAJOR		  		5
#define FW_VER_MINOR		  		0
#define FW_VER_REVISION				2
#define FW_VER_LABEL		  		6

//*************************************************************************************************
//*************************************************************************************************






//*************************************************************************************************

#define MEAS_INFO_ADDR				        0x002000	//8K
#define NVM_0_ADDR_DEVICE_CONFIG	        0x003000	//12K
#define NVM_1_ADDR_CALIB_TEMPERATURE	    0x004000	//16K
#define NVM_2_ADDR_CALIB_OXY	            0x005000	//20K
#define NVM_3_ADDR_CALIB_PRESSURE		    0x006000	//24K
#define NVM_4_ADDR_CALIB_VIBRATION			0x007000	//28K
#define NVM_5_ADDR_CALIB_DIST				0x008000	//32K
#define NVM_6_ADDR_DEV_MEM					0x009000	//36K
#define NVM_7_ADDR_CALIB_VIB_ANGLE			0x00A000	//40K

#define NVM_8_ADDR_FW_UPDATE_FLAG		    0x00B000	//44K
#define NVM_FW_HEAD							0x00C000	//48K
#define FW_MEM_ADDR							0x00D000	//52K
                                            //0x080000  -- 460K
                                            
#define NVM_9_ADDR                          0x08D000    //564
#define NVM_10_ADDR                         0x08E000    //568
#define NVM_11_ADDR                         0x08F000    //572
#define NVM_12_ADDR                         0x090000    //576

//                                          0x09F000    //636

#define NVM_LOG_START_ADDR                  0x0A0000    //640K
#define NVM_LOG_AREA_SIZE                   0x080000    //512 KByte

                                            //0x100000    //1024K

#define DATA_RECODER_START_ADDR				0x200000	//2M
#define DATA_RECODER_MAX_ITEM		        (DATA_RECODER_SIZE/32-130)

#define V_ID_TEMP_BAT				1
#define V_ID_VAC_PRES				2
#define V_ID_OXYGEN_A				3
#define V_ID_SPEED  				4
#define V_ID_WIDTH                  5
#define V_ID_ANGLE                  6


//*************************************************************************************************



//*************************************************************************************************
//**                                                                                             **
//**									    I7  				                                 **
//**                                                                                             **
//*************************************************************************************************
#if DEV_TYPE == DEV_TYPE_I7
#define FW_NAME				"iProfile_I7" 
#define FW_INFO				\
"iProfile I7\r\n\
"


#define DATA_RECODER_SIZE		    			(2*1024*1024) //1024K 12CH 0.1S 40min,
#define DATA_RECODER_TOTAL_ITEM					((60*1024*1024)/DATA_RECODER_SIZE)
#define MAX_RECODER_GROUP_CNT		            15

#define WIFI_ENABLE		                        1

#define USE_TEMPERATURE                         1
#define USE_VIBRATE                             1
#define USE_VIBRATE_REALTIME                    0

#define USE_V_VACUUM_1                          0
#define USE_V_OXY_1                             0
#define USE_V_SPEED                             0
#define USE_V_WIDTH_1                           0

#define V_DATA_CNT					            1
#define V_DATA_LIST                             V_ID_TEMP_BAT

//*************************************************************************************************



//*************************************************************************************************
//**                                                                                             **
//**									    XP1 				                                 **
//**                                                                                             **
//*************************************************************************************************
#elif DEV_TYPE == DEV_TYPE_XP
#define FW_NAME				"iProfile_XP1" //
#define FW_INFO				\
"iProfile XP\r\n\
"

#define DATA_RECODER_SIZE		    			(1536*1024) //1024K 12CH 0.1S 40min,
#define DATA_RECODER_TOTAL_ITEM					((60*1024*1024)/DATA_RECODER_SIZE)
#define MAX_RECODER_GROUP_CNT		            1

#define WIFI_ENABLE		                        1

#define USE_TEMPERATURE                         1
#define USE_VIBRATE                             0
#define USE_VIBRATE_REALTIME                    0

#define USE_V_VACUUM_1                          1
#define USE_V_OXY_1                             0
#define USE_V_SPEED                             0
#define USE_V_WIDTH_1                           0

#define V_DATA_CNT					            1
#define V_DATA_LIST                             V_ID_TEMP_BAT


//*************************************************************************************************


//*************************************************************************************************
//**                                                                                             **
//**									    Mini				                                 **
//**                                                                                             **
//*************************************************************************************************
#elif DEV_TYPE == DEV_TYPE_MINI
#define FW_NAME				"iProfile_mini" //
#define FW_INFO				\
"iProfile Mini\r\n\
"
               
#define DATA_RECODER_SIZE		    			(2*1024*1024) //1024K 12CH 0.1S 40min,
#define DATA_RECODER_TOTAL_ITEM					((60*1024*1024)/DATA_RECODER_SIZE)
#define MAX_RECODER_GROUP_CNT		            1

#define WIFI_ENABLE		                        0

#define USE_TEMPERATURE                         1
#define USE_VIBRATE                             1
#define USE_VIBRATE_REALTIME                    0

#define USE_V_VACUUM_1                          0
#define USE_V_OXY_1                             0
#define USE_V_SPEED                             0
#define USE_V_WIDTH_1                           0

#define V_DATA_CNT					            1
#define V_DATA_LIST                             V_ID_TEMP_BAT
//*************************************************************************************************



//*************************************************************************************************
//**                                                                                             **
//**									    Vacuum				                                 **
//**                                                                                             **
//*************************************************************************************************
#elif DEV_TYPE == DEV_TYPE_VACUUM
#define FW_NAME				"iVacuum" //
#define FW_INFO				\
"iProfile Vacuum\r\n\
"
#define DATA_RECODER_SIZE		    			(1536*1024) //1024K 12CH 0.1S 40min,
#define DATA_RECODER_TOTAL_ITEM					((60*1024*1024)/DATA_RECODER_SIZE)
#define MAX_RECODER_GROUP_CNT		            1

#define WIFI_ENABLE					            0

#define USE_TEMPERATURE                         1
#define USE_VIBRATE                             0
#define USE_VIBRATE_REALTIME                    0

#define USE_V_VACUUM_1                          1
#define USE_V_OXY_1                             0
#define USE_V_SPEED                             0
#define USE_V_WIDTH_1                           0

#define V_DATA_CNT					            1
#define V_DATA_LIST                             V_ID_TEMP_BAT
//*************************************************************************************************



//*************************************************************************************************
//**                                                                                             **
//**									    Oxygen				                                 **
//**                                                                                             **
//*************************************************************************************************
#elif DEV_TYPE == DEV_TYPE_OXYGEN_STD 

#define USE_NEW_HARD                            1

#define DATA_RECODER_SIZE		    			(1536*1024) //1024K 12CH 0.1S 40min,
#define DATA_RECODER_TOTAL_ITEM					((60*1024*1024)/DATA_RECODER_SIZE)
#define MAX_RECODER_GROUP_CNT		            1

#define WIFI_ENABLE					            0


#define USE_TEMPERATURE                         1
#define USE_VIBRATE                             1
#define USE_VIBRATE_REALTIME                    0

#define USE_V_VACUUM_1                          0
#define USE_V_OXY_1                             1
#define USE_V_SPEED                             0
#define USE_V_WIDTH_1                           0

#define V_DATA_CNT					            3
#define V_DATA_LIST                             V_ID_TEMP_BAT,V_ID_OXYGEN_A,V_ID_SPEED

#if USE_NEW_HARD == 0
#define FW_NAME				"iProfile_ROS" //
#else 
#define FW_NAME				"iProfile_ROS" //
#endif
#define FW_INFO				\
"iProfile_ROS STD\r\n\
"


//*************************************************************************************************
//**                                                                                             **
//**									    RPT				                                     **
//**                                                                                             **
//*************************************************************************************************
#elif DEV_TYPE == DEV_TYPE_RPT_STD 

#define USE_NEW_HARD                            1

#define DATA_RECODER_SIZE		    			(1536*1024) //1024K 12CH 0.1S 40min,
#define DATA_RECODER_TOTAL_ITEM					((60*1024*1024)/DATA_RECODER_SIZE)
#define MAX_RECODER_GROUP_CNT		            1

#define WIFI_ENABLE					            0

#define USE_TEMPERATURE                         1
#define USE_VIBRATE                             1
#define USE_VIBRATE_REALTIME                    0

#define USE_V_VACUUM_1                          0
#define USE_V_OXY_1                             0
#define USE_V_SPEED                             0
#define USE_V_WIDTH_1                           1

#define V_DATA_CNT					            4
#define V_DATA_LIST                             V_ID_ANGLE,V_ID_TEMP_BAT,V_ID_ANGLE,V_ID_WIDTH

#if USE_NEW_HARD == 0
#define FW_NAME				"RPT_STD_OLD" //
#else 
#define FW_NAME				"RPT_STD_NEW" //
#endif
#define FW_INFO				\
"RPT_STD\r\n\
"

//*************************************************************************************************
#else
#error "aa"
#endif

#define DEV_FUNC_LIST_L                         (USE_TEMPERATURE<<0)|(USE_VIBRATE<<1)|(USE_V_VACUUM_1<<2)|(0<<3)|(USE_V_OXY_1<<4)|(0<<5)|(USE_V_SPEED<<6)|(USE_V_WIDTH_1<<7)

typedef enum
{
	CMD_SUCCESS = 1,
	CMD_BUSY,
	CMD_UNSUPPORT,
	CMD_INVPARAMS,
	CMD_ERROR,
	CMD_CONTINUE,
	CMD_ERRMEM,
	CMD_ERRSTS,
}CMD_STS;

typedef struct _frame_head
{
	uint8_t Command;
	uint8_t Proces;
	uint8_t DataLength;
	uint8_t	DeviceStatus;
	uint8_t *pDataBuf;
}frame_head_t;

#define CMD_SET_ERROR(head,err)			{head->DataLength = 2;head->DeviceStatus = err;head->pDataBuf[0] = ((__LINE__)>>0)&0xFF;head->pDataBuf[0] = ((__LINE__)>>8)&0xFF;}
#define CMD_SET_OK(head,len)			{head->DataLength = len;head->DeviceStatus = CMD_SUCCESS;}


typedef int32_t (*cb_command)(frame_head_t *p_cmd_head);

#define DEVICE_TYPE							21		//iProfileMini
#define PART_TYPE		  					1		//1:device/2:module
#define COMM_CMD_MAX						64

/* Exported constants ------------------------------------------------------------------*/
#define APPLICATION_ADDRESS				0x00004000      //16K
#define FIRMWARE_INFO_ADDR             	0x00003C00
#define DEVICE_INFO_ADDR				(FIRMWARE_INFO_ADDR + 0x200)
#define DEVICE_CALCULATE_ADDR 			(FIRMWARE_INFO_ADDR )

#define FIRM_INFO_HEAD_ADDR				0x00008010

extern struct tm VCAM_RTC;

/* Exported macro ----------------------------------------------------------------------*/
extern uint8_t DEV_UID[];
extern uint8_t Device_SerialID[];
//extern DEVICE_INFO g_DeviceInfo;

extern int WIFI_Connetstatusflag;		// WiFi״̬�������ж��Ƿ���ʾ����ʹ��WiFiע��
/* Exported functions ----------------------------------------------------------------- */
void SetSysClock(void);
void WDG_Config(void);
void WDG_Refresh(void);
void BSP_Init(void);
void BSP_uDelay(uint16_t x);



#endif
/********************************(C)COPYRIGHT 2016 RSEStudio ****************************/
/*****************************************END OF FILE************************************/
